package com.supermap.dataservice.user.dao;

import com.supermap.dataservice.entity.Menu;
import org.apache.ibatis.annotations.*;

/**
 * @author xiaolu
 * @date 2018/7/9 上午10:19
 */
@Mapper
public interface MenuMapper {

    /**
     * 数据库查询用户信息
     *
     * @param menuId 菜单ID
     * @return 用户实体
     */
    @Select("SELECT * FROM menu WHERE id=#{id};")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "parent", column = "pid",
                    one = @One(select = "com.supermap.dataservice.mysql.mapper.MenuMapper.findMenuById"))}
    )
    Menu findMenuById(@Param("id") int menuId);

    /**
     *
     *
     * 增加菜单
     *
     * @param menu 待增加菜单
     * @return 插入状态
     */
    @Insert("INSERT INTO menu SET (name,pid) VALUES (#{menu.name},#{menu.parent.id});")
    int insertMenu(@Param("menu") Menu menu);
}
